﻿using UnityEngine;
using GraphProcessor;

namespace IQIGame.Onigao.GamePlay.Editors
{
    [System.Serializable, NodeMenuItem(LevelEditorConst.Level + "/" + LevelEditorConst.Prefab + "/" + LevelEditorConst.LevelService, typeof(LevelServiceGraph))]
    public class LevelServicePrefabNode : IDGenerateNode
    {
        public override bool isRenamable => true;
        public override Color color => new Color(0.8f, 1, 0.8f);

        [Output("执行", false)] public LevelServiceEditor execution;
        public override string name => LevelEditorConst.LevelService + LevelEditorConst.Prefab;
        [InspectorName("默认关闭")]public bool defaultDisable;
        [InspectorName("延时执行(毫秒)")]public int delay;
        [InspectorName("储存延时")]public bool saveDelay;
        [LevelServiceEditorCustomProperty("Se", "打断类型")]public int breakType;
        
        public string prefabkey;

        protected override void Process()
        {
            base.Process();
            var rServiceConfig = new EditorLevelServiceUnitConfig()
            {
                delay = this.delay,
                serviceBreak = new EditorLevelServiceBreakConfig()
                {
                    breakType = this.breakType
                },
                name = this.GetCustomName(),
                defaultDisable = this.defaultDisable,
                saveDelay = this.saveDelay
            };
            var rPrefabSource = new EditorLevelServicePrefabSource()
            {
                key = this.prefabkey,
                prefab = rServiceConfig
            };
            this.execution = new LevelServiceEditor()
            {
                serviceConfig = rServiceConfig
            };
            LevelServiceBlackboard.Instance.AddServicePrefab(rPrefabSource);
        }
    }
}